﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Nuzzle.Protocol
{
    public class NetworkMessage : IDisposable
    {
        public NetworkMessageID ProtocolID = NetworkMessageID.None;

        public BigEndianReader ReaderBuffer { get; set; }
        public BigEndianWriter WriterBuffer { get; set; }

        /// <summary>
        /// Initialize new sended packet
        /// </summary>
        /// <param name="id">Dofus Protocol ID</param>
        public NetworkMessage(NetworkMessageID id)
        {
            this.ProtocolID = id;
            this.WriterBuffer = new BigEndianWriter();
        }

        /// <summary>
        /// Initialize new received packet
        /// </summary>
        /// <param name="buffer">Buffer Reader ( BigEndianReader )</param>
        public NetworkMessage(NetworkMessageReader buffer)
        {
            this.ReaderBuffer = buffer.Reader;
        }

        public void Dispose()
        {
            if(WriterBuffer != null)
                WriterBuffer.Dispose();
            if(ReaderBuffer != null)
                ReaderBuffer.Dispose();
        }
    }
}
